package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.domain.ErpWarehouse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ErpStorageArea;
import com.ruoyi.service.IErpStorageAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库区信息管理Controller
 * 
 * @author zhp
 * @date 2025-07-18
 */


@RestController
@RequestMapping("/storage/area")
public class ErpStorageAreaController extends BaseController
{
    @Autowired
    private IErpStorageAreaService erpStorageAreaService;

    /**
     * 查询库区信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('storage:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpStorageArea erpStorageArea)
    {
        startPage();
        List<ErpStorageArea> list = erpStorageAreaService.selectErpStorageAreaList(erpStorageArea);
        return getDataTable(list);
    }

    /**
     * 导出库区信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('storage:area:export')")
    @Log(title = "库区信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpStorageArea erpStorageArea)
    {
        List<ErpStorageArea> list = erpStorageAreaService.selectErpStorageAreaList(erpStorageArea);
        ExcelUtil<ErpStorageArea> util = new ExcelUtil<ErpStorageArea>(ErpStorageArea.class);
        util.exportExcel(response, list, "库区信息管理数据");
    }

    /**
     * 获取库区信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('storage:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(erpStorageAreaService.selectErpStorageAreaById(id));
    }

    /**
     * 新增库区信息管理
     */
    @PreAuthorize("@ss.hasPermi('storage:area:add')")
    @Log(title = "库区信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpStorageArea erpStorageArea)
    {
        return toAjax(erpStorageAreaService.insertErpStorageArea(erpStorageArea));
    }

    /**
     * 修改库区信息管理
     */
    @PreAuthorize("@ss.hasPermi('storage:area:edit')")
    @Log(title = "库区信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpStorageArea erpStorageArea)
    {
        return toAjax(erpStorageAreaService.updateErpStorageArea(erpStorageArea));
    }

    /**
     * 删除库区信息管理
     */
    @PreAuthorize("@ss.hasPermi('storage:area:remove')")
    @Log(title = "库区信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(erpStorageAreaService.deleteErpStorageAreaByIds(ids));
    }


//    查询仓库表信息
    @PreAuthorize("@ss.hasPermi('storage:warehouse:query')")
    @GetMapping("/warehouse")
    public AjaxResult getWarehouseInfo() {
        return success(erpStorageAreaService.selectErpWarehouse());
    }


    //查询仓库表中id和仓库名称
    @PreAuthorize("@ss.hasPermi('storage:warehouse:query')")
    @GetMapping("/warehouseOfIdAndName"+"/{warehouseId}")
    public ErpWarehouse getWarehouseOfIdAndName(@PathVariable("warehouseId") Long warehouseId) {
        return erpStorageAreaService.selectErpWarehouseOfIdAndName(warehouseId);
    }







}
